package com.charlotte.study.gupao.chain.auth.builderchain;

import com.charlotte.study.gupao.chain.auth.genera.Member;

/**
 * @author junjie.ding
 * @date 2020/3/16
 */
public abstract class Handler<T> {

    protected Handler chain;

    private void next(Handler handler){
        this.chain = handler;
    }

    public abstract void doHandler(Member member);

    public static class Builder<T>{
        private Handler<T> head;
        private Handler<T> tail;

        public Builder<T> addHandler(Handler<T> handler){
            if(this.head == null){
                this.head = this.tail = handler;
                return this;
            }
            this.tail.next(handler);
            this.tail = handler;
            return this;
        }

        public Handler<T> build(){
            return this.head;
        }
    }
}
